﻿function Dictionary() {
    this.add = add;
    this.datastore = new Array();
    this.find = find;
    this.remove = remove;
    this.showAll = showAll;
    this.count = count;
    this.clear = clear;
}
function add(key, value) {//增加数据
    this.datastore[key] = value;
}
function find(key) {//查找
    return this.datastore[key];
}
function remove(key) {//删除
    delete this.datastore[key];
}
function showAll() {//显示所有数据
    for (var key in this.datastore) {
        if (this.datastore.hasOwnProperty(key)) {
            console.log(key, ":", this.datastore[key]);
        }
    }
}
function count() {//字典中的数据计数
    var n = 0;
    for (var key in this.datastore) {
        if (this.datastore.hasOwnProperty(key)) {
            n++;
        }
    }
    return n;
}
function clear() {//清空字典
    for (var key in this.datastore) {
        if (this.datastore.hasOwnProperty(key)) {
            delete this.datastore[key];
        }
    }
}